package com.hsnn.medstgmini.pro.plan.service.impl;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hsnn.medstgmini.pro.plan.dao.WsjPriceAdjustDao;
import com.hsnn.medstgmini.pro.plan.service.WsjPriceAdjustManager;
import com.hsnn.medstgmini.util.DateUtil;
import com.hsnn.medstgmini.util.Pagination;

@Service
public class WsjPriceAdjustManagerImpl implements WsjPriceAdjustManager{
	
	@Autowired
	private  WsjPriceAdjustDao wsjPriceAdjustDao;
	
	/**
	 * @category 验证调价计划名称是否重复
	 * @auth wangbing
	 * @return true重复  flase不重复
	 * @date 2015-11-13 09:10:03
	 */
	@Override
	public boolean validateRepeat(String name,String id){
		return wsjPriceAdjustDao.validateRepeat(name, id);
	}
	
	/**
	 * @category 新增调价计划
	 * @auth wangbing
	 * @return 
	 * @date 2015-11-13 09:59:19
	 */
	@Transactional
	@Override
	public void addPriceAdjPlan(Pagination page){
		wsjPriceAdjustDao.addPriceAdjPlan(page);
	}
	
	/**
	 * @category 获取未处理调价计划列表
	 * @auth wangbing
	 * @return
	 * @date 2015-11-13 08:32:31
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getNoPriceAdjPlanList(Pagination page){
		List<Map<String,Object>> list = (List<Map<String, Object>>) wsjPriceAdjustDao.getNoPriceAdjPlanList(page).getRows();
		for(Map<String,Object> data : list){
			Object executeCat = data.get("executeCat");
			data.put("executeCat", executeCat==null?"":Integer.parseInt(executeCat.toString())==1?"手动执行":"自动执行");
			data.put("createDatetime", DateUtil.dateTime((Timestamp)data.get("createDatetime")));
			data.put("executeDatetime", DateUtil.dateTime((Timestamp)data.get("executeDatetime")));
			data.put("updDatetime", DateUtil.dateTime((Timestamp)data.get("updDatetime")));
		}
		page.setRows(list);
		return page;
	}
	
	/**
	 * @category 根据id获取调价计划
	 * @auth wangbing
	 * @return
	 * @date 2015-11-13 08:32:31
	 */
	@Override
	public Map<String,Object> getPriceAdjPlanById(String id){
		Map<String,Object> data = wsjPriceAdjustDao.getPriceAdjPlanById(id);
		Object executeCat = data.get("executeCat");
		data.put("executeCat", executeCat==null?"":Integer.parseInt(executeCat.toString())==1?"手动执行":"自动执行");
		data.put("createDatetime", DateUtil.dateTime((Timestamp)data.get("createDatetime")));
		data.put("executeDatetime", DateUtil.dateTime((Timestamp)data.get("executeDatetime")));
		data.put("updDatetime", DateUtil.dateTime((Timestamp)data.get("updDatetime")));
		return data;
	}
	
	/**
	 * @category 编辑调价计划
	 * @auth wangbing
	 * @return 
	 * @date 2015-11-13 09:59:19
	 */
	@Transactional
	@Override
	public void editPriceAdjPlan(Pagination page){
		wsjPriceAdjustDao.editPriceAdjPlan(page);
	}
	
	/**
	 * 
	 * @category 获取调价计划明细列表
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@Override
	public Pagination getPriceAdjPlanDetailList(Pagination page) {
		return wsjPriceAdjustDao.getPriceAdjPlanDetailList(page);
	}
	
	/**
	 * 
	 * @category 获取未加入调价计划商品列表
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@Override
	public Pagination getPriceAdjPlanDurgList(Pagination page) {
		return wsjPriceAdjustDao.getPriceAdjPlanDurgList(page);
	}
	
	/**
	 * 
	 * @category 加入调价计划
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@Transactional
	@Override
	public int addDetail(List<Map<String,String>> list){
		return wsjPriceAdjustDao.addDetail(list);
	}
	
	/**
	 * 
	 * @category 删除调价计划明细
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@Transactional
	@Override
	public int deleteDetail(List<String> list){
		return wsjPriceAdjustDao.deleteDetail(list);
	}
	
	/**
	 * 
	 * @category 保存调价计划明细
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@Transactional
	@Override
	public int saveDetail(List<Map<String,String>> list){
		return wsjPriceAdjustDao.saveDetail(list);
	}
	
	/**
	 * @category 执行调价计划
	 * @auth wangbing
	 * @date 2015年6月24日
	 */
	@Override
	public void runPriceAdjPlan(Pagination page) {
		wsjPriceAdjustDao.runPriceAdjPlan(page);
	}
	
	/**
	 * @category 获取已处理调价计划列表
	 * @auth wangbing
	 * @return
	 * @date 2015-11-13 08:32:31
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getPriceAdjPlanList(Pagination page){
		List<Map<String,Object>> list = (List<Map<String, Object>>) wsjPriceAdjustDao.getPriceAdjPlanList(page).getRows();
		for(Map<String,Object> data : list){
			Object executeCat = data.get("executeCat");
			data.put("executeCat", executeCat==null?"":Integer.parseInt(executeCat.toString())==1?"手动执行":"自动执行");
			data.put("createDatetime", DateUtil.dateTime((Timestamp)data.get("createDatetime")));
			data.put("executeDatetime", DateUtil.dateTime((Timestamp)data.get("executeDatetime")));
			data.put("updDatetime", DateUtil.dateTime((Timestamp)data.get("updDatetime")));
		}
		page.setRows(list);
		return page;
	}
	
	/**
	 * 
	 * @category 获取已处理调价计划明细列表
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@Override
	public Pagination getPriceDetailList(Pagination page) {
		return wsjPriceAdjustDao.getPriceDetailList(page);
	}
	
	/**
	 * 
	 * @category 获取历史调价信息
	 * @auth wangbing
	 * @return Pagination
	 * @date 2015年6月23日
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getGoodsHistoryPriceList(Pagination page) {
		List<Map<String,Object>> list = (List<Map<String, Object>>) wsjPriceAdjustDao.getGoodsHistoryPriceList(page).getRows();
		for(Map<String,Object> data : list){
			data.put("executeDatetime", DateUtil.dateTime((Timestamp)data.get("executeDatetime")));
			data.put("addDatetime", DateUtil.dateTime((Timestamp)data.get("addDatetime")));
		}
		page.setRows(list);
		return page;
	}
}
